﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TP2
{
    public partial class CorrespondentForm : Form
    {
        int addSumm;
        Int64 Deposit;
        int idBank;
        public CorrespondentForm(int id_bank)
        {
            idBank = id_bank;
            DBWorkClass dbwork = new DBWorkClass();
            Deposit = dbwork.SelectFromCorrespondent(id_bank);
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                addSumm = Convert.ToInt32(textBoxAdd.Text);
                Deposit = Deposit + addSumm;
                if (Deposit >= 0)
                {
                    DBWorkClass dbWork = new DBWorkClass();
                    dbWork.UpdateFromCorrespondent(idBank, Deposit);
                }
                else { MessageBox.Show("грабёж"); }
                this.Close();
            }
            catch (FormatException) { MessageBox.Show("ошибка во входных данных"); }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CorrespondentForm_Load(object sender, EventArgs e)
        {
            labelDeposit.Text = Deposit.ToString();
        }
    }
}
